<h2 class="ui dividing header">添加成员</h2>
<div class="ui message">
	<div class="header">小提示</div>
	<ul class="list">
		<li>密码需要超过6位</li>
		<li>邮箱必须是未注册过的</li>
	</ul>
</div>
<div class="ui icon message" id="wait">
	<i class="notched circle loading icon"></i>
	<div class="content">
		<div class="header">等一会</div>
		<p id="waitMessage"></p>
	</div>
</div>
<div class="ui success message" id="result">
	<p id="message"></p>
</div>
<form class="ui form" id="form">
	<h4 class="ui dividing header">查找</h4>
	<div class="field">
		<label>姓名</label>
		<div class="field">
			<input id="name" type="text" name="name" placeholder="姓名">
		</div>
		<label>邮箱</label>
		<div class="field">
			<input id="mail" type="text" name="mail" placeholder="邮箱">
		</div>
		<label>密码</label>
		<div class="field">
			<input id="password" type="password" name="password" placeholder="密码">
		</div>
	</div>
	<div class="ui segment">
		<div class="field">
			<div class="ui toggle checkbox">
				<input id="sendMail" type="checkbox" name="sendverifyemail"
					tabindex="0" class="hidden"> <label>发送验证邮件</label>
			</div>
		</div>
		<div class="field">
			<div class="ui toggle checkbox">
				<input id="passdirectly" type="checkbox" name="passdirectly"
					tabindex="0" class="hidden"> <label>是否直接通过邮件验证</label>
			</div>
		</div>
	</div>
	<div class="ui error message"></div>
	<div class="ui submit button" tabindex="0">提交</div>
</form>
<script type="text/javascript">
closeWaitMessage();
closeResult();
var sendMail;
$('.ui.checkbox').checkbox();
$('.ui.form')
.form({
	 fields: {
	      name: {identifier: 'name', rules: [{type: 'empty', prompt: '姓名不能为空'}]},
	      mail: {identifier: 'mail', rules: [{type: 'email', prompt: '邮箱输入必须符合格式'}, {type: 'empty', prompt: '邮箱不能为空'}]},
	      password: {identifier: 'password', rules: [{type: 'minLength[6]', prompt: '密码必须大于六位'}]}
	  }
  }
);
$("#form").submit(function(e){
    e.preventDefault();
    if($("#form").attr("class")=="ui form success"){
    	  console.log($('#form').serialize());
    	  turnWaitMessage("我们正在将你的表单提交到服务器处理。。可能需要一些时间。");
    	  $("form input").attr("readonly","true");
 		submit1();
    }
});
function submit1() {
	 sendMail=$("sendMail").prop("checked");
	 console.log("submit1");
    $.ajax({
        type: "POST",
        dataType: "json",
        url:"admin.php?model=member&ajax=true&op=addpost",
        data:$('#form').serialize(),
        complete:function (e) {
        	  var json = eval(e.responseJSON);
        	 dealData(json["state"],json["message"]);
        	  $("#form")[0].reset();
         	  $("form input").removeAttr("readonly");
        	  closeWaitMessage();
        }
    });
}
function dealData(state,message){
	turnResultMessage(state,message);
}
function turnWaitMessage(message){
	$("#waitMessage").html(message);
	$("#wait").show();
}
function turnResultMessage(state,message){
	if(state==1){$("#result").attr("class","ui success message");}
	else{$("#result").attr("class","ui error message");}
	$("#message").html(message);
	$("#result").show();
}
function closeWaitMessage(){
	$("#wait").hide();
}
function closeResult(){
	$("#result").hide();
}
</script>